import axios from "axios";
import { getToken } from "@/utils/auth";
import type { AxiosRequestConfig } from "axios";

console.log(import.meta.env.BASE_URL);
const service = axios.create({
  baseURL: "/api",
  timeout: 50000,
  headers: { "Content-Type": "application/json" },
});
service.interceptors.request.use((config) => {
  const isToken = (config.headers || {}).isToken === false;
  if (getToken() && !isToken) {
    (config as any).headers.Authorization = "Bearer " + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
  }
  return config;
});
service.interceptors.response.use((res) => {
  return res.data;
});

export default service;
